<!-- 右边图标跳转 页面 -->
<template>
	<view class="">
		<view class="margin-top_50rpx">
			<view class="tabSwitch flex-between  ">
				<view v-for="(item,index) in tabSwitchList" :key="index" @click.stop="tabSwitchCk(index)">
					<view :class="currentIndex == index ? 'activeBtn flex font-weight_bold' : 'transitionBtn flex'"
						:style="{ color: currentIndex == index ? '#333333' : '#898888' }" style="font-size: 27rpx;">
						{{ item.tabName }}
					</view>
				</view>
			</view>
		</view>
		<view class=" margin-top_30rpx ">
			<sunui-navbar v-if="tabList" :items="tabList" lineHeight="60rpx" :isCenter="true" :currentIndex="tabIndex"
				padding="1rpx" :size="130" activeLineBg="#FF0000" textAlign="center" activeColor="#333333"
				activeLineWidth="45%" activeDirection="center" activeLineHeight="8rpx" :margin="1"
				@change="getChange"></sunui-navbar>
		</view>
		<mescroll-body ref="mescrollRef " @init="mescrollInit" :down="downOption" @down="downCallback" @up="upCallback">
			<view class="orderList " v-for="(item,index) in orderList" :key="index">
				<view class="flex-between">
					<view :class="item.is_status==1?'font-overflow width35':'' ">
						订单号：{{item.log_no?item.log_no:item.a_log_no}}
					</view>



					<view class="flex" style="color: #FF0000;" v-if="currentIndex==0">
						{{orderStatusFn(item.is_status)}} <text style="margin-left: 10rpx;"
							v-if="item.is_status==1">剩余:</text> <uni-countdown v-if="item.is_status==1" color="#FF0000"
							:show-day="true" :day="item.refundTime.days" :hour="item.refundTime.hours"
							:minute="item.refundTime.minutes" :second="item.refundTime.seconds" />
					</view>
					<view class="flex" style="color: #FF0000;" v-if="currentIndex==1">
						{{orderStatusFn2(item.is_status)}} <text style="margin-left: 10rpx;"
							v-if="item.is_status==1">剩余:</text> <uni-countdown v-if="item.is_status==1" color="#FF0000"
							:show-day="true" :day="item.refundTime.days" :hour="item.refundTime.hours"
							:minute="item.refundTime.minutes" :second="item.refundTime.seconds" />
					</view>
					<view class="flex" style="color: #FF0000;" v-if="currentIndex==2">
						{{orderStatusFn3(item.is_status)}} <text style="margin-left: 10rpx;"
							v-if="item.is_status==1">剩余:</text> <uni-countdown v-if="item.is_status==1" color="#FF0000"
							:show-day="true" :day="item.refundTime.days" :hour="item.refundTime.hours"
							:minute="item.refundTime.minutes" :second="item.refundTime.seconds" />
					</view>
					<view class="flex" style="color: #FF0000;" v-if="currentIndex==3">
						{{orderStatusFn4(item.is_status)}} <text style="margin-left: 10rpx;"
							v-if="item.is_status==1">剩余:</text> <uni-countdown v-if="item.is_status==1" color="#FF0000"
							:show-day="true" :day="item.refundTime.days" :hour="item.refundTime.hours"
							:minute="item.refundTime.minutes" :second="item.refundTime.seconds" />
					</view>
				</view>

				<view class="v-shop-cart margin-top_30rpx">
					<view class="flex-align-center">
						<!-- <image class="border10" :src="detailList.foods_img"></image> -->
						<image class="border10" :src="item.pic_url">
						</image>
						<view class="flex-columns v-content flex1" style="height: 148rpx;">
							<view class="flex-between">
								<!-- <view class="v-name">{{ detailList.foods_name }}</view> -->
								<view class="v-name">{{item.goods_name}}</view>
							</view>
							<!-- 需修改样式‘上下底部对齐’ -->
							<!-- <text v-if="detailList.service_desc">周期服务：{{ detailList.service_desc }}</text> -->
							<view style="color: #888888;">规格：{{item.spec_name}}</view>
							<view class="flex-start-center" v-if="currentIndex==0">
								<view v-if="item.is_status==2" class="v-price margin-right_30rpx">当前价:￥{{item.total}}
								</view>
								<view v-if="item.is_status==3||item.is_status==5"
									class="groupBuying flex font-size_22rpx">
									{{item.max_number}}人团购
								</view>
								<view v-if="item.is_status==1||item.is_status==0"
									class="groupBuying flex font-size_22rpx">
									当前价:￥{{item.total}}
								</view>

								<view v-if="item.is_status==6" class="v-price flex font-size_22rpx">
									已退:￥{{item.money}}
								</view>

							</view>
							<view class="flex-start-center" v-if="currentIndex==1">
								<view class="v-price margin-right_30rpx">秒杀价:￥{{item.total}}
								</view>

							</view>
							<view class="flex-start-center" v-if="currentIndex==2">
								<view class="v-price margin-right_30rpx">
									当前价:￥{{item.money>item.total?item.money:item.total}}
								</view>

							</view>
							<view class="flex-start-center" v-if="currentIndex==3">
								<view class="v-price margin-right_30rpx">众筹价格(每人)：￥{{item.money}}
								</view>

							</view>


						</view>
					</view>
				</view>
				<view class="flex-between margin-top_50rpx padding-bottom_30rpx"
					:class="item.invoice_data.is_status==3?'border-bottom-ECECEC':''">
					<view class="flex-start-center " v-if="currentIndex==0">
						<view class="flex-start-center">
							<view class="flex-between v-p-share">
								<view class="v-m-width not-font-overflow flex1">
									<block v-for="(img, index) in imgList" :key="index">
										<image v-if="index<3" class="pt_img" :src="img"></image>
									</block>

								</view>

							</view>


						</view>
						<text class="font-size_40rpx">...</text>
					</view>
					<view class="" v-else>

					</view>
					<view class=" flex-between" v-if="currentIndex==0">
						<view class="gay-whiteBtn flex margin-right_16rpx" v-if="(item.is_status==1)"
							@click="cancelOrder(item.id)">
							取消订单
						</view>

						<view class="gay-whiteBtn flex margin-right_16rpx" @click="viewDetail(item.id)"
							v-if="item.is_status==0||item.is_status==3||item.is_status==4||item.is_status==5||item.is_status==6">
							查看详情
						</view>
						<view class="gay-whiteBtn flex margin-right_16rpx" @click="goEvaluateList(item.goods_id)"
							v-if="(item.is_status==4)">
							查看评价
						</view>
						<view class="red-whiteBtn flex margin-right_16rpx" v-if="item.is_status==5&&item.is_invoice==1"
							@click="viewInvoice(item.invoice_data)">
							查看发票
						</view>
						<view class="red-whiteBtn flex margin-right_16rpx" @click="comment(item.id,item.groupon_id)"
							v-if="(item.is_status==3||item.is_status==5)">
							立即评价
						</view>

						<view class="red-whiteBtn flex margin-right_16rpx" @click="issueInvoice(item.id)"
							v-if="(item.is_status==3||item.is_status==4)&&item.need_invoice==1&&item.need_invoice==0">
							开发票
						</view>
						<view class="red-whiteBtn flex margin-right_16rpx" @click="issueInvoice(item.id)"
							v-if="(item.is_status==3||item.is_status==4)&&item.is_invoice==1&&item.need_invoice==1&&item.invoice_data.is_status==1">
							发票审核中
						</view>
						<view class="red-whiteBtn flex margin-right_16rpx" @click="issueInvoice(item.id)"
							v-if="(item.is_status==3||item.is_status==4)&&item.is_invoice==1&&item.need_invoice==1&&item.invoice_data.is_status==3">
							发票已驳回
						</view>
						<view class="red-whiteBtn flex margin-right_16rpx" v-if="item.is_status==2||item.is_status==1"
							@click="joinActivities(Number(currentIndex)+1,item.groupon_id,1)">
							立即购买
						</view>
						<button open-type="share" class="btncss " @click.stop="shareShop(item,1)">
							<view class="red-whiteBtn flex margin-right_16rpx" v-if="item.is_status==2">
								邀请好友
							</view>
						</button>

					</view>
					<view class=" flex-between" v-if="currentIndex==1">
						<view class="gay-whiteBtn flex margin-right_16rpx" v-if="(item.is_status==1)"
							@click="cancelOrder(item.id)">
							取消订单
						</view>

						<view class="gay-whiteBtn flex margin-right_16rpx" @click="viewDetail(item.id)"
							v-if="item.is_status==0||item.is_status==2||item.is_status==4||item.is_status==5||item.is_status==6">
							查看详情
						</view>
						<view class="gay-whiteBtn flex margin-right_16rpx" @click="goEvaluateList(item.goods_id)"
							v-if="(item.is_status==4)">
							查看评价
						</view>
						<view class="red-whiteBtn flex margin-right_16rpx" @click="issueInvoice(item.id)"
							v-if="(item.is_status==2||item.is_status==4)&&item.is_invoice==0&&item.need_invoice==1">
							开发票
						</view>
						<view class="red-whiteBtn flex margin-right_16rpx" @click="issueInvoice(item.id)"
							v-if="(item.is_status==2||item.is_status==4)&&item.is_invoice==1&&item.need_invoice==1&&item.invoice_data.is_status==1">
							发票审核中
						</view>
						<view class="red-whiteBtn flex margin-right_16rpx" @click="issueInvoice(item.id)"
							v-if="(item.is_status==2||item.is_status==4)&&item.need_invoice==1&&item.is_invoice==1&&item.invoice_data.is_status==3">
							发票已驳回
						</view>
						<view class="red-whiteBtn flex margin-right_16rpx" v-if="item.is_status==5&&item.is_invoice==1"
							@click="viewInvoice(item.invoice_data)">
							查看发票
						</view>





						<view class="red-whiteBtn flex margin-right_16rpx" @click="comment(item.id,item.seckill_id)"
							v-if="(item.is_status==2||item.is_status==5)">
							立即评价
						</view>
						<view class="red-whiteBtn flex margin-right_16rpx" v-if="item.is_status==1"
							@click="joinActivities(Number(currentIndex)+1,item.seckill_id,1,item)">
							立即购买
						</view>

					</view>
					<view class=" flex-between" v-if="currentIndex==2">
						<view class="gay-whiteBtn flex margin-right_16rpx" v-if="(item.is_status==1)"
							@click="cancelOrder(item.id)">
							取消订单
						</view>

						<view class="gay-whiteBtn flex margin-right_16rpx" @click="viewDetail(item.id)"
							v-if="item.is_status==0||item.is_status==3||item.is_status==4||item.is_status==5||item.is_status==6">
							查看详情
						</view>
						<view class="gay-whiteBtn flex margin-right_16rpx" @click="goEvaluateList(item.goods_id)"
							v-if="(item.is_status==4)">
							查看评价
						</view>
						<view class="red-whiteBtn flex margin-right_16rpx" @click="issueInvoice(item.id)"
							v-if="(item.is_status==3||item.is_status==4)&&item.need_invoice==1">
							开发票
						</view>
						<view class="red-whiteBtn flex margin-right_16rpx" @click="issueInvoice(item.id)"
							v-if="(item.is_status==3||item.is_status==4)&&item.is_invoice==1&&item.need_invoice==1&&item.invoice_data.is_status==1">
							发票审核中
						</view>
						<view class="red-whiteBtn flex margin-right_16rpx" @click="issueInvoice(item.id)"
							v-if="(item.is_status==3||item.is_status==4)&&item.is_invoice==1&&item.need_invoice==1&&item.invoice_data.is_status==3">
							发票已驳回
						</view>
						<view class="red-whiteBtn flex margin-right_16rpx" v-if="item.is_status==5&&item.is_invoice==1"
							@click="viewInvoice(item.invoice_data)">
							查看发票
						</view>
						<view class="red-whiteBtn flex margin-right_16rpx" @click="comment(item.id,item.bargains_id)"
							v-if="(item.is_status==3||item.is_status==5)">
							立即评价
						</view>
						<view class="red-whiteBtn flex margin-right_16rpx" v-if="item.is_status==2"
							@click="joinActivities(Number(currentIndex)+1,item.bargains_id,2)">
							邀请好友
						</view>

						<view class="red-whiteBtn flex margin-right_16rpx" v-if="item.is_status==2||item.is_status==1"
							@click="joinActivities(Number(currentIndex)+1,item.bargains_id,1)">
							立即购买
						</view>
					</view>
					<view class=" flex-between" v-if="currentIndex==3">
						<view class="gay-whiteBtn flex margin-right_16rpx" v-if="(item.is_status==1)"
							@click="cancelOrder(item.id)">
							取消订单
						</view>

						<view class="gay-whiteBtn flex margin-right_16rpx" @click="viewDetail(item.id)"
							v-if="item.is_status==0||item.is_status==2||item.is_status==3||item.is_status==4||item.is_status==5||item.is_status==6">
							查看详情
						</view>
						<view class="gay-whiteBtn flex " @click="goEvaluateList(item.goods_id)"
							v-if="(item.is_status==4)">
							查看评价
						</view>
						<view class="red-whiteBtn flex margin-right_16rpx" @click="issueInvoice(item.id)"
							v-if="(item.is_status==3||item.is_status==4)&&item.need_invoice==1">
							开发票
						</view>
						<view class="red-whiteBtn flex margin-right_16rpx" @click="issueInvoice(item.id)"
							v-if="(item.is_status==3||item.is_status==4)&&item.is_invoice==1&&item.need_invoice==1&&item.invoice_data.is_status==1">
							发票审核中
						</view>
						<view class="red-whiteBtn flex margin-right_16rpx" @click="issueInvoice(item.id)"
							v-if="(item.is_status==3||item.is_status==4)&&item.is_invoice==1&&item.need_invoice==1&&item.invoice_data.is_status==3">
							发票已驳回
						</view>



						<view class="red-whiteBtn flex margin-right_16rpx" v-if="item.is_status==5&&item.is_invoice==1"
							@click="viewInvoice(item.invoice_data)">
							查看发票
						</view>
						<view class="red-whiteBtn flex margin-right_16rpx" @click="comment(item.id,item.presell_id)"
							v-if="(item.is_status==3||item.is_status==5)">
							立即评价
						</view>


						<button open-type="share" class="btncss " @click.stop="shareShop(item,4)">
							<view class="red-whiteBtn flex margin-right_16rpx" v-if="item.is_status==2">
								邀请好友
							</view>
						</button>
						<view class="red-whiteBtn flex margin-right_16rpx" v-if="item.is_status==1"
							@click="joinActivities(Number(currentIndex)+1,item.presell_id,1,item)">
							立即购买
						</view>
					</view>

				</view>
				<view class="margin-top_30rpx" v-if="item.invoice_data.reason&&item.invoice_data.is_status==3">
					<text style="color: #FF0000;">驳回原因：</text><text>{{item.invoice_data.reason}}</text>

				</view>


			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import antiThrottling from '@/utils/antiThrottling.js';
	export default {
		data() {
			return {
				orderList: [],
				imgList: [
					'/static/avatar.png',
					'/static/avatar.png',
					'/static/avatar.png',
					'/static/avatar.png',
					'/static/avatar.png',
					'/static/avatar.png',
				],
				detailInfo: {},
				activitType: 1,

				currentIndex: 0,
				tabIndex: 0,
				tabSwitchList: [{
						id: 1,
						tabName: '拼团订单'

					},
					{
						id: 2,
						tabName: '秒杀订单'

					},
					{
						id: 3,
						tabName: '砍价订单'

					},
					{
						id: 4,
						tabName: '众筹订单'

					}
				],
				// 拼团
				tabList: [{
						name: '全部',
						id: ''
					}, {
						name: '已取消',
						id: 0
					},
					{
						name: '待付款',
						id: 1,

					},
					{
						name: '拼团中',
						id: 2,

					},
					{
						name: '已完成',
						id: 3,

					},
					{
						name: '已评价',
						id: 4,

					},
					{
						name: '已发票',
						id: 5,

					},
					{
						name: '已退款',
						id: 6,

					}
				],

				is_status: '',
				detailShare: {},
				type: ''
			};
		},
		onLoad(options) {
			if (options.tabSwitchOrder) {
				this.currentIndex = options.tabSwitchOrder
				this.tabIndex = options.tabOrder
				this.getChange(this.tabIndex)
				this.tabSwitchCk(this.currentIndex)
			}


			this.randomUserFn()
		},
		onShow() {
			this.userInfos()
			antiThrottling.releaseKey('submit');
			this.$nextTick(() => {
				this.mescroll?.resetUpScroll();
			})
		},
		computed: {

			// 订单状态 
			orderStatusFn: function() {
				return function(status) {

					let orderStatus = '';
					// status订单状态（0.待付款 1.待接单 2.已接单 3.服务中 4.已完成 5.已取消/退款)
					orderStatus =
						status == 0 ? '已取消' : status == 1 ? '待付款' : status == 2 ? '拼团中' : status == 3 ? '已完成' :
						status == 4 ? '已评价' : status == 5 ? '已开票' : '已退款';


					return orderStatus;
				};
			},
			orderStatusFn2: function() {
				return function(status) {

					let orderStatus = '';
					// status订单状态（0.待付款 1.待接单 2.已接单 3.服务中 4.已完成 5.已取消/退款)
					orderStatus =
						status == 0 ? '已取消' : status == 1 ? '待付款' : status == 2 ? '已完成' : status == 4 ? '已评价' :
						status == 5 ? '已开票' : '已退款';


					return orderStatus;
				};
			},
			orderStatusFn3: function() {
				return function(status) {

					let orderStatus = '';
					// status订单状态（0.待付款 1.待接单 2.已接单 3.服务中 4.已完成 5.已取消/退款)
					orderStatus =
						status == 0 ? '已取消' : status == 1 ? '待付款' : status == 2 ? '砍价中' : status == 3 ? '已完成' :
						status == 4 ? '已评价' : status == 5 ? '已开票' : '已退款';


					return orderStatus;
				};
			},
			orderStatusFn4: function() {
				return function(status) {

					let orderStatus = '';
					// status订单状态（0.待付款 1.待接单 2.已接单 3.服务中 4.已完成 5.已取消/退款)
					orderStatus =
						status == 0 ? '已取消' : status == 1 ? '待付款' : status == 2 ? '众筹中' : status == 3 ? '已完成' :
						status == 4 ? '已评价' : status == 5 ? '已开票' : '已退款';


					return orderStatus;
				};
			},
		},

		onPageScroll(ev) {



		},
		methods: {
			async userInfos() {
				const result = await this.$http.get({
					url: this.$api.userInfo,
					data: {
						// 用户id
						uid: uni.getStorageSync('uid'),
						// 上级id
						pid: '',

					}
				});
				if (result.errno == 0) {
					uni.setStorageSync('user', result.data);

				}
			},
			shareShop(i, type) {
				this.detailShare = i;
				this.type = type
				// 小程序分享 与button的open-type 使用(接口)
			},
			onShareAppMessage(res) {
				console.log(res)
				if (res.from === 'button') {
					// 来自页面内分享按钮
					// this.addShare();
					if (this.type == 1) {
						this.detailShare.shareId = this.detailShare.groupon_id
						console.log(this.detailShare.shareId)
					}
					if (this.type == 4) {

						this.detailShare.shareId = this.detailShare.presell_id
					}
					return {
						
				
						// 自定义分享标题

						title: this.detailShare.share_title?this.detailShare.share_title: this.detailShare.name ? this.detailShare.name : this.detailShare.goods_name,
						imageUrl:this.detailShare.share_pic?this.detailShare.share_pic: this.detailShare.pic_url,

						path: '/pages/detail/detail?goods_id=' + this.detailShare.shareId + '&type=' + this.type +
							'&uid=' + uni.getStorageSync('uid') ? uni.getStorageSync('uid') : '',

					};
				} else {
					return {
						// 自定义分享标题

						
						title: this.detailShare.share_title?this.detailShare.share_title: this.detailShare.name ? this.detailShare.name : this.detailShare.goods_name,
						imageUrl:this.detailShare.share_pic?this.detailShare.share_pic: this.detailShare.pic_url,

						path: '/pages/detail/detail?goods_id=' + this.detailShare.shareId + '&type=' + this.type +
							'&uid=' + uni.getStorageSync('uid') ? uni.getStorageSync('uid') : '',

					};
				}


			},

			issueInvoice(id) {

				this.$sun.navGo('/pages/confirmOrder/issueInvoice', {
					orderId: id,
					type: this.currentIndex + 2
				});
			},
			//取消订单
			async cancelOrder(order_id) {

				uni.showModal({
					title: '提示',
					content: '是否删除取消订单',
					success: async (res) => {
						if (res.confirm) {
							let cancelApi = this.currentIndex == 0 ? this.$api.grouponOrderCancel : this
								.currentIndex == 1 ? this.$api.seckillOrderCancel : this.currentIndex ==
								2 ? this.$api.bargainsOrderCancel : this.$api.presellOrderCancel
							const result = await this.$http.get({
								url: cancelApi,
								data: {
									// 用户id
									uid: uni.getStorageSync('uid'),
									order_id: order_id


								},


							})
							if (result.errno == 0) {
								this.$sun.toast(result.message, 'none')

								console.log()
								setTimeout(() => {
									this.mescroll.resetUpScroll();
								}, 500)
							} else {

								this.$sun.toast(result.message, 'none')
							}
						} else if (res.cancel) {

						}
					}
				});

			},
			formatTimeDifferenceOrder(timestamp) {
				// 获取当前时间的时间戳（以秒为单位）
				const currentTimestamp = Math.floor(Date.now() / 1000);

				// 计算时间差（以秒为单位）
				let timeDifference = timestamp - currentTimestamp;

				// 如果时间差是负数，表示目标时间已经过去，返回0
				if (timeDifference < 0) {
					return {
						days: '00',
						hours: '00',
						minutes: '00',
						seconds: '00'
					};
				}

				// 计算天数
				const days = Math.floor(timeDifference / (24 * 60 * 60));
				timeDifference %= (24 * 60 * 60);

				// 计算小时
				const hours = Math.floor(timeDifference / (60 * 60));
				timeDifference %= (60 * 60);

				// 计算分钟
				const minutes = Math.floor(timeDifference / 60);

				// 剩余的秒数
				const seconds = timeDifference % 60;

				// 返回格式化后的时间差
				return {
					days: days,
					hours: hours,
					minutes: minutes,
					seconds: seconds
				};
			},
			// 立即评论
			comment(id, goodsId) {
				console.log('立即评论')
				this.$sun.navGo('/pages/orderMessage/addSpeak/addSpeak', {

					type: this.currentIndex + 2,
					orderId: id
				});
			},
			// 1 type 支付购买 2.邀请好友
			joinActivities(index, id, type, item = '') {

				console.log('55555555555555555555555555555555555555555')
				this.activitType = index
				if (this.activitType == 1) {
					this.grouponGoodsDetail(id, type)

				} else if (this.activitType == 2) {
					this.seckillGoodsDetail(id, type, item)
				} else if (this.activitType == 3) {
					this.bargainsGoodsDetail(id, type)
				} else if (this.activitType == 4) {
					console.log('众筹')
					this.presellGoodsDetail(id, type, item)
				}
			},
			confirmOrder() {



				setTimeout(() => {
					uni.hideLoading()
					this.$sun.navGo('/pages/confirmOrder/confirmOrder');
				}, 350)
			},
			inviteBargaining() {
				setTimeout(() => {
					this.$sun.navGo('/pages/activityPgae/bargainAssistancePage')
				}, 350)

			},
			// 众筹详情
			async presellGoodsDetail(id, type, item) {
				const result = await this.$http.get({
					url: this.$api.presellGoodsDetail,
					data: {
						// 用户id
						uid: uni.getStorageSync('uid'),
						// 产品id
						presell_id: id,

					}
				});
				if (result.errno == 0) {
					this.detailInfo = result.data;

					if (type == 1) {
						antiThrottling.uniDoFunc({
							// 键名
							key: 'submit',
							success: async () => {
								//锁定
								antiThrottling.lockKey('submit');

								this.pays(item)

								console.log('111')


							}
						});

					} else {
						this.inviteBargaining()
					}


				}
			},
			// 拼团详情
			async grouponGoodsDetail(id, type) {
				const result = await this.$http.get({
					url: this.$api.grouponGoodsDetail,
					data: {
						// 用户id
						uid: uni.getStorageSync('uid'),
						// 产品id
						groupon_id: id,

					}
				});
				if (result.errno == 0) {
					this.detailInfo = result.data;


					if (type == 1) {
						this.confirmOrder()
					} else {
						this.inviteBargaining()
					}

					// // 增加浏览量
					// this.addBrowse();
				}
			},
			// 秒杀详情
			async seckillGoodsDetail(id, type, item) {
				const result = await this.$http.get({
					url: this.$api.seckillGoodsDetail,
					data: {
						// 用户id
						uid: uni.getStorageSync('uid'),
						// 产品id
						seckill_id: id,

					}
				});
				if (result.errno == 0) {
					this.detailInfo = result.data;
					if (type == 1) {
						// this.confirmOrder()
						// 直接支付
						console.log(item)

						antiThrottling.uniDoFunc({
							// 键名
							key: 'submit',
							success: async () => {
								//锁定
								antiThrottling.lockKey('submit');

								this.pays(item)

								console.log('111')


							}
						});

					} else {
						this.inviteBargaining()
					}
				}

			},
			async pays(item) {
				const result = await this.$http.get({
					url: this.$api.wxPay,
					data: {

						// 支付金额
						price: item.money,
						// 订单编号
						log_no: item.log_no,
						// opid
						openid: wx.getStorageSync('user').openid,

						name: item.goods_name ? item.goods_name : ''
					}
				});
				if (result.errno == 0) {
					this.$sun.title('支付');
					const pay = result.data;
					this.$sun.wePay(
						pay,
						async success => {
								this.getChange(3)
								// uni.setStorageSync('use_integral', use_integral);
								antiThrottling.releaseKey('submit');



							},
							async cancel => {
								this.getChange(2)
								antiThrottling.releaseKey('submit');

							}
					);
				} else {
					this.$sun.toast(result.message);
					antiThrottling.releaseKey('submit');
				}
			},
			// 砍价详情
			async bargainsGoodsDetail(id, type) {
				uni.showLoading({
					title: '加载中'
				});
				const result = await this.$http.get({
					url: this.$api.bargainsGoodsDetail,
					data: {
						// 用户id
						uid: uni.getStorageSync('uid'),
						// 产品id
						bargains_id: id,

					}
				});
				if (result.errno == 0) {
					this.detailInfo = result.data;
					if (type == 1) {
						console.log('==================砍价')
						this.confirmOrder()
					} else {
						this.inviteBargaining()
					}

				}
			},
			viewInvoice(data) {
				if (data.is_status == 1) {
					this.$sun.toast('当前未开发票', 'none')

				} else {
					this.$sun.navGo('/pages/viewInvoice/viewInvoice', {
						fpUrl: data.pic_url
					});
				}
			},
			async randomUserFn() {
				const result = await this.$http.get({
					url: this.$api.randomUser,
					data: {
						psize: 6


					}
				});
				if (result.errno == 0) {

					console.log(result.data)
					this.imgList = result.data

				}

			},
			async upCallback(scroll) {
				console.log(this.currentIndex, 'upCallbackupCallbackupCallback')
				let orderListApi = (Number(this.currentIndex) + 1) == 1 ? this.$api.grouponOrderList : (Number(this
							.currentIndex) +
						1) == 2 ? this.$api.seckillOrderList : (Number(this.currentIndex) + 1) == 3 ? this.$api
					.bargainsOrderList : this.$api.presellOrderList

				const result = await this.$http.get({
					url: orderListApi,
					data: {
						// 用户id
						uid: uni.getStorageSync('uid'),
						page: scroll.num,
						psize: 10,
						is_status: this.is_status,


					}
				});
				if (result.errno == 0) {

					this.mescroll.endByPage(result.data.list.length, result.totalPage);
					if (scroll.num == 1) this.orderList = [];
					this.orderList = this.orderList.concat(result.data.list);

					this.orderList.forEach((item) => {
						if (item.is_status == 1) {
							item.refundTime = this.formatTimeDifferenceOrder(item.end_time)
							console.log(item.refundTime)
						}

					})
					console.log()


				}
			},
			viewDetail(id) {
				this.$sun.navGo('/pages/orderMessage/orderDetail/orderDetail', {
					orderId: id,
					type: this.currentIndex == 0 ? 2 : this.currentIndex == 1 ? 3 : this.currentIndex == 2 ? 4 : 5
				});
			},
			goEvaluateList(goods_id) {
				console.log('111')
				this.$sun.navGo('/pages/detail/allEvaluateList', {
					goods_id: goods_id
				});

			},


			tabSwitchCk(index) {

				this.currentIndex = index
				console.log(this.currentIndex)

				if (this.currentIndex == 0) {
					this.tabList = [{
							name: '全部',
							id: ''
						}, {
							name: '已取消',
							id: 0
						},
						{
							name: '待付款',
							id: 1,

						},
						{
							name: '拼团中',
							id: 2,

						},
						{
							name: '已完成',
							id: 3,

						},
						{
							name: '已评价',
							id: 4,

						},
						{
							name: '已发票',
							id: 5,

						},
						{
							name: '已退款',
							id: 6,

						}
					]
				} else if (this.currentIndex == 2) {
					this.tabList = [{
							name: '全部',
							id: ''
						}, {
							name: '已取消',
							id: 0
						},
						{
							name: '待付款',
							id: 1,

						},
						{
							name: '砍价中',
							id: 2,

						},
						{
							name: '已完成',
							id: 3,

						},
						{
							name: '已评价',
							id: 4,

						},
						{
							name: '已发票',
							id: 5,

						},
						{
							name: '已退款',
							id: 6,

						}
					]
				} else if (this.currentIndex == 3) {
					this.tabList = [{
							name: '全部',
							id: ''
						}, {
							name: '已取消',
							id: 0
						},
						{
							name: '待付款',
							id: 1,

						},
						{
							name: '众筹中',
							id: 2,

						},
						{
							name: '已完成',
							id: 3,

						},
						{
							name: '已评价',
							id: 4,

						},
						{
							name: '已发票',
							id: 5,

						},
						{
							name: '已退款',
							id: 6,

						}
					]
				} else {
					this.tabList = JSON.parse(JSON.stringify([{
							name: '全部',
							id: ''
						}, {
							name: '已取消',
							id: 0
						},
						{
							name: '待付款',
							id: 1,

						},
						{
							name: '已完成',
							id: 2,

						},

						{
							name: '已评价',
							id: 4,

						},
						{
							name: '已发票',
							id: 5,

						},
						{
							name: '已退款',
							id: 6,

						}
					]))
				}
				this.mescroll.resetUpScroll();
			},
			getChange(index) {
				this.tabIndex = index;
				if (this.currentIndex == 1) {
					this.is_status = (index == 0 ? '' : index == 1 ? 0 : index == 2 ? 1 : index == 3 ? 2 : index);
				} else {
					this.is_status = (index == 0 ? '' : index - 1);
				}


				console.log(index, this.is_status)
				this.mescroll.resetUpScroll();

			},
		}
	};
</script>

<style lang="less">
	.orderList {
		padding: 30rpx;
		// height: 410rpx;
		border-radius: 20rpx;
		margin: 0 25rpx;
		background: rgb(255, 255, 255);
		margin-top: 30rpx;
	}

	.red-whiteBtn {
		box-sizing: border-box;
		border: 2rpx solid rgb(255, 0, 0);
		border-radius: 192rpx;
		width: 160rpx;
		height: 70rpx;
		background: rgb(255, 255, 255);
		color: #FF0000;
	}

	.gay-whiteBtn {
		box-sizing: border-box;
		border: 2rpx solid rgb(244, 244, 244);
		border-radius: 192rpx;
		width: 152rpx;
		height: 70rpx;
		color: #000000;
		background: rgb(255, 255, 255);
	}

	.v-p-share {
		padding: 2rpx 2rpx 0 2rpx;

		.v-m-width {
			margin-right: 20rpx;

			.pt_img {
				width: 50rpx;
				height: 50rpx;
				margin-right: -20rpx;
				border-radius: 50%;
			}
		}

		.v-share-friend {
			text {
				color: #294d7d;
				font-size: 24rpx;
				padding-right: 50rpx;
			}

			view {
				color: #ffffff;
				width: 154rpx;
				height: 58rpx;
			}
		}

		.v-share-friend2 {
			text {
				color: #294d7d;
				font-size: 24rpx;
			}
		}
	}

	.v-shop-cart {

		// border-bottom: 2rpx solid #f7f7f7;

		image {
			width: 140rpx;
			height: 140rpx;
			margin-right: 20rpx;
		}

		.v-content {
			.v-name {
				font-size: 32rpx;
				font-weight: bold;
			}

			text {
				color: #8f8f8f;
				// padding: 10rpx 0;
				padding: 10rpx 0 16rpx;
			}

			.v-price {
				color: #FF0000;
				font-size: 28rpx;
			}

			.groupBuying {
				min-width: 110rpx;
				height: 40rpx;
				padding: 10rpx;
				border-radius: 12rpx;
				color: #fff;
				background: rgb(255, 0, 0);
			}

			.viewOrder {
				color: #666666;
				border-radius: 12rpx;
				width: 132rpx;
				font-size: 26rpx;
				height: 52rpx;
				background: rgb(245, 245, 245);
			}
		}
	}

	.tabSwitch {
		margin: 0 75rpx;
		height: 68rpx;
		border-radius: 176rpx;

		background: #EDEDED;

		.activeBtn {
			padding: 0 20rpx;
			width: 150rpx;
			height: 68rpx;
			border-radius: 158rpx;

			background: rgb(255, 255, 255);
		}

		.transitionBtn {
			padding: 0 20rpx;
			width: 150rpx;
			height: 68rpx;
			border-radius: 158rpx;

			// background: rgb(255, 255, 255);
		}
	}
</style>